package com.noriental.okcalls.controller;

import com.alibaba.fastjson.JSONObject;
import com.noriental.okcalls.wechat.callback.MsgAdapter;
import com.noriental.okcalls.wechat.callback.WxMsgDispatchCenter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/***
 * *   ____  ___________  ___________           ________   ____  __.  _____ _____.___.
 * *   \   \/  /\______ \ \_   _____/           \_____  \ |    |/ _| /  _  \\__  |   |
 * *    \     /  |    |  \ |    __)     ______   /   |   \|      <  /  /_\  \/   |   |
 * *    /     \  |    `   \|     \     /_____/  /    |    \    |  \/    |    \____   |
 * *   /___/\  \/_______  /\___  /              \_______  /____|__ \____|__  / ______|
 * *    	 \_/        \/     \/                       \/        \/       \/\/
 * *
 * *   功能描述：
 * *
 * *   @DATE    2020-10-10
 * *   @AUTHOR  qiyubin
 ***/
@Slf4j
@RestController
@RequestMapping("/api/wx")
public class WxCallbackController {

    /**
     * 请组装对应的dispatch
     */
    @Autowired
    WxMsgDispatchCenter demoDispatchCenter;

    @PostMapping(value = "/callBack")
    public String recMsg(@RequestBody String xml, HttpServletRequest req) {
        String s = req.getParameter("s");
        log.info("msg is  {},security is {}", JSONObject.toJSONString(MsgAdapter.analysisMsg(xml)), s);
        demoDispatchCenter.dispatch(xml);
        return "ok";
    }

}



